package com.calvin.study.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.calvin.study.ocr.service.IBizService;
import com.calvin.study.ocr3.context.StrategyContext;
import com.calvin.study.ocr3.strategy.IStrategy;
import com.calvin.study.ocr6.ProcessorChain;
import com.calvin.study.ocr6.Product;


@RestController
@RequestMapping(value = "/ocr")
public class OcrController {
	
	@Autowired
	private IBizService bizService;
	
	@GetMapping(value = "/test1")
	public String test1() {
		try {
			bizService.parseData();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return "FAILE";
		}
		return "SUCCESS";
	}
	
	@Autowired
	private StrategyContext strategyContext;
	
	@GetMapping(value = "/test3")
	public String test3() {
		try {
			IStrategy strategy  = strategyContext.getStrategy("d474fe7f054608b6273a48790cb81d80");
			strategy.parseMx();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return "FAILE";
		}
		return "SUCCESS";
	}
	
	
	
	@Autowired
	private ProcessorChain processorChain;
	
	@GetMapping(value = "/test4")
	public String test4() {
		try {
			Product product = new Product();
			product.setTemp("01");
			boolean p = processorChain.process(product);
			System.out.println(p);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return "FAILE";
		}
		return "SUCCESS";
	}

}
